/**
 * @fileOverview StateController Modul file
 * 
 * @author Adam Hořčica horcicaa@gmail.com
 * @url $HeadURL: http://ahs-gadgets.googlecode.com/svn/tags/bb-counters/1.0/src/state_controller.js $
 * @revision $Id: state_controller.js 47 2008-02-09 20:30:13Z horcicaa $
 */

/**
 * Control of counter widget detail styte
 */ 
var StateController = {

  /** Usre  Preferents (_IG_Prefs object) */ 
  prefs: null,
  
  /** Detail state container */
  state: {},
  
  /**
   * Initialite StateController  
   * @param {object} prefs Preferents object (_IG_Prefs)
   */     
  init: function(prefs)
  {
    this.prefs = prefs;
    this.state = JSON.parse(prefs.getString("state"));
  },
  
  /**
   * Return detail state of counter widget with ID
   * @param {number} id Counter ID
   * @return {boolean} State of detail (true for open details)       
   */     
  getState: function(id)
  {
    if(this.state['c' + id] !== null)
    {
      return !! this.state['c' + id];
    }
    else
    {
      return false;
    }
  },
  
  /**
   * Save state of counter by ID to user perefs.
   * @param {number} id Counter ID   
   * @param {boolean} State of detail   
   */     
  setState: function(id, state)
  {
    this.state['c' + id] = state;
    this.prefs.set("state", JSON.stringify(this.state));
  }

};
